﻿<html>
  <head>
    <title>TIScript - WebSocket object</title>
    <meta name="generator" content="h-smile:richtext"/>
  </head>
<body>
  <h1>WebSocket object</h1>
  <p>It is a basic implementation of <a href="http://tools.ietf.org/html/rfc6455">WebSocket protocol</a> .</p>
  <dl>
    <h2>Properties</h2>
    <h2>Methods</h2>
    <dt>connect</dt>
    <dd>
      <p><strong>( url</strong>: string [,<strong> timeout</strong>: duration] <strong>)</strong> : WebSocket</p>
      <p>Static constructor of the WebSocket. Accepts websocket schema URL: &quot;ws://domain/path&quot;. Returns new socket in INITIAL state. The <em>timeout</em> is a connection timeout. If timeout is exceeded while connecting error event will be generated.</p></dd>
    <dt>on</dt>
		<dd>
      <p><strong>( event</strong>: string<strong>, callback</strong>: function<strong>)</strong> : this</p>
      <p>Subscribe &nbsp;callback on one of socket events:</p>
      <ul>
        <li><strong>&quot;connect&quot;</strong> -&gt; function(), socket just connected to the host;</li>
        <li><strong>&quot;text&quot;</strong> -&gt; function(data), text packet received, data contains string; &nbsp;</li>
        <li><strong>&quot;binary&quot;</strong> -&gt; function(data), binary packet received, data contains Bytes object;</li>
        <li><strong>&quot;error&quot;</strong> -&gt; function(errmsg), error occured;</li>
        <li><strong>&quot;close&quot;</strong> -&gt; function(), socket was closed;</li></ul>
      <p>The event name may contain &quot;.namespace&quot; part that can be used in .off() call.</p></dd>
    <dt>once</dt>
    <dd>
      <p><strong>( event</strong>: string<strong>, callback</strong>: function<strong> )</strong> : this</p>
      <p>Same as on() but subscribes the callback for once execution ( record is auto removed after first callback )</p></dd>
    <dt>off</dt>
    <dd>
      <p><strong>( event</strong>: string | <strong>callback</strong>: function<strong> )</strong> : this</p>
      <p>Unsubscribe callback either by its name or by its function reference.</p>
      <p>Event name may contain only namespace part, so this: <code>socket.off(&quot;.namespace&quot;)</code> will unsubscribe all handlers that were set with that namespace.</p></dd>
    <dt>send</dt>
    <dd>
      <p><strong>( data</strong>: string | Bytes&nbsp;<strong>)</strong></p>
      <p>The method sends message as a text or binary frame (message) to the WebSocket server.</p></dd>
    <dt>close</dt>
    <dd>
      <p><strong>( )</strong></p>
      <p>Sends disconnect request to the server and closes the socket.</p></dd></dl>
</body>
</html>